package main

import (
	"encoding/json"
	"flag"
	"fmt"
	"github.com/hibiken/asynq"
	"t-go-zero/service/asynq/jobtype"
	"t-go-zero/service/asynq/scheduler/internal/config"
	"t-go-zero/service/asynq/scheduler/internal/svc"

	"github.com/zeromicro/go-zero/core/conf"
)

var configFile = flag.String("f", "etc/asynq-scheduler.yaml", "the config file")

func main() {
	flag.Parse()

	var c config.Config
	conf.MustLoad(*configFile, &c)

	// 中间件注册
	svcContext := svc.NewServiceContext(c)

	// 定时时间
	every := fmt.Sprintf("@every %vs", 10)

	user := jobtype.User{
		Id:   999,
		Name: "11111",
	}

	data, err := json.Marshal(user)
	if err != nil {
		fmt.Println("序列化失败")
	}

	svcContext.AsynqScheduler.Register(every, asynq.NewTask(jobtype.Add, data))

	svcContext.AsynqScheduler.Run()

}
